<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$time_start = getMicro_Time();
include_once("Stock_ListResult.php");
$time_end = getMicro_Time();

$fp = @file($strTemplatePath."Stock_List.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

	if(!$isShowSupple){
		$fp = str_replace('Director_index.php', 'Stock_index.php', $fp);
		$fp = preg_replace("/<!--@ SuppleContent Start @\/\/-->.+<!--@ SuppleContent End @\/\/-->/s", "", $fp);
		$fp = preg_replace("/<!-- @ Director Cont1 Start @ \/\/-->.+<!-- @ Director Cont1 End @ \/\/-->/s", "", $fp);
		$fp = preg_replace("/<!-- @ Director Cont2 Start @ \/\/-->.+<!-- @ Director Cont2 End @ \/\/-->/s", "", $fp);
		$fp = preg_replace("/<!-- @ Director Cont3 Start @ \/\/-->.+<!-- @ Director Cont3 End @ \/\/-->/s", "", $fp);
		$fp = preg_replace("/<!-- @ Director Cont4 Start @ \/\/-->.+<!-- @ Director Cont4 End @ \/\/-->/s", "", $fp);
	}
	if(!$isShowComSupple){
		$fp = preg_replace("/<!--@ CompanySupple Start @\/\/-->.+<!--@ CompanySupple End @\/\/-->/s", "", $fp);
		$fp = preg_replace("/<!--@ StockReport Start @\/\/-->.+<!--@ StockReport End @\/\/-->/s", "", $fp);
	}else{
		$fp = preg_replace("/<!--@ DirectorReport Start @\/\/-->.+<!--@ DirectorReport End @\/\/-->/s", "", $fp);
	}

	$fp = str_replace("{Show_Lotto_Type}", $_data["LottoID"], $fp);
	$fp = str_replace("{Show_GambleID}", $_data["GambleID"], $fp);
	$fp = str_replace("{Show_Bet_Type}", $_data["Bet_Type"], $fp);
	$fp = str_replace("{Show_PayupDate_0}", $data["PayupDate_x"][0], $fp);
	$fp = str_replace("{Show_PayupDate_1}", $data["PayupDate_x"][1], $fp);
	$fp = str_replace("{LottoContent}", (empty($_data["LottoID"]))?"All":$_arrLotto[$_data["LottoID"]]["Lotto_".$_intLang], $fp);
	$fp = str_replace("{BetTypeContent}", (empty($_data["Bet_Type"]))?"All":$_arrBet_Type[$_arrLotto[$_data["LottoID"]]["LType"]][$_data["Bet_Type"]], $fp);
	$fp = str_replace("{Show_Types}", ((empty($_data["Types"]))?"Stock":$_data["Types"]), $fp);
	while(list($k, $v) = each($_strAccount_Stock)){
		$fp = str_replace("{".$k."}", $v, $fp);
	}

	if($isShowSupple){
		preg_match("/<!--@ SuppleStockResult Start @\/\/-->(.+)<!--@ SuppleStockResult End @\/\/-->/s", $fp, $SA);
		preg_match("/<!--@ SuppleDirectorResult Start @\/\/-->(.+)<!--@ SuppleDirectorResult End @\/\/-->/s", $fp, $SG);
	}
	if($isShowComSupple){
		preg_match("/<!--@ SuppleComResult Start @\/\/-->(.+)<!--@ SuppleComResult End @\/\/-->/s", $fp, $CA);
		preg_match("/<!--@ SuppleCompanyResult Start @\/\/-->(.+)<!--@ SuppleCompanyResult End @\/\/-->/s", $fp, $CG);
	}
	preg_match("/<!--@ StockResult Start @\/\/-->(.+)<!--@ StockResult End @\/\/-->/s", $fp, $A);
	preg_match("/<!--@ DirectorResult Start @\/\/-->(.+)<!--@ DirectorResult End @\/\/-->/s", $fp, $G);
	preg_match("/<!--@ ALLResult Start @\/\/-->(.+)<!--@ ALLResult End @\/\/-->/s", $fp, $S);
	$sumtotals = 0;
	$sumMemStake = 0;
	$sumSubIncome = 0;
	$sumSubRateResult = 0;
	$sumMainRateResult = 0;
	$sumStockRateResult = 0;
	$sumrealMemStake = 0;
	$sumDirectorRateResult = 0;
	$sumDirectorComm = 0;
	$Ctotals = 0;
	$CMemStake = 0;
	$CSubIncome = 0;
	$CSubRateResult = 0;
	$CMainRateResult = 0;
	$CStockRateResult = 0;
	$CDirectorRateResult = 0;
	$CDirectorComm = 0;
	$MainID = "";
	if(is_array($arrRows[0])){
		while(list($k, $Rows) = each($arrRows[0])){
			$DirectorID = $Rows -> DirectorID;
			$tmpA = $A[1];
			//總帳
			if($intReportType == 0){
				$tmpA = str_replace("{Show_Stock}", $arrAccount[$Rows -> StockID], $tmpA);
				//if(!empty($intStockID) && $intStockID != $Rows -> StockID){
				//	$tmpA = str_replace("Account('{Show_StockID}')", "void(0);", $tmpA);
				//}else{
					if($intStockID == $Rows -> StockID)$tmpA = str_replace("crig", "crigplus", $tmpA);
					$tmpA = str_replace("{Show_StockID}", $Rows -> StockID, $tmpA);
				//}
			//分類帳
			}elseif($intReportType == 1){
				$tmpA = str_replace("{Show_Stock}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $tmpA);
				$tmpA = str_replace("Account('{Show_StockID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 0)", $tmpA);
			}
			$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
			$tmpA = str_replace("{MemStake}", sprintf("%.1f",$Rows -> MemStake), $tmpA);
			$tmpA = str_replace("{SubIncome}", sprintf("%.1f",$Rows -> SubIncome), $tmpA);
			$tmpA = str_replace("{SubRateResult}", sprintf("%.1f",$Rows -> SubRateResult), $tmpA);
			$tmpA = str_replace("{realMemStake}", sprintf("%.1f",$Rows -> realMemStake), $tmpA);
			$tmpA = str_replace("{realMemStake%}", sprintf("%.4f",$Rows -> realMemStake / $CrealMemStake), $tmpA);
			$tmpA = str_replace("{MainRateResult}", sprintf("%.1f",$Rows -> MainRateResult), $tmpA);
			$tmpA = str_replace("{StockRateResult}", sprintf("%.1f",$Rows -> StockRateResult), $tmpA);
			$tmpA = str_replace("{StockResult}", sprintf("%.1f",$Rows -> StockResult), $tmpA);
			if($isShowSupple){
				$tmpA = str_replace("{DirectorResult}", sprintf("%.1f",$Rows -> DirectorResult), $tmpA);
				$tmpA = str_replace("{DirectorStockRate}", $Rows -> StockRate - $Rows -> DirectorRate, $tmpA);
				$tmpA = str_replace("{DirectorRate}", $Rows -> DirectorRate, $tmpA);
				$tmpA = str_replace("{DirectorComm}", sprintf("%.2f",$Rows -> DirectorComm), $tmpA);
				$tmpA = str_replace("{DirectorRateWin}", sprintf("%.1f",$Rows -> StockRateResult - $Rows -> DirectorRateResult - $Rows -> DirectorComm), $tmpA);
				$tmpA = str_replace("{DirectorWin}", sprintf("%.1f",$Rows -> StockRateResult - $Rows -> DirectorRateResult), $tmpA);
				$tmpA = str_replace("{DirectorRateResult}", sprintf("%.1f",$Rows -> DirectorRateResult), $tmpA);
			}
			$strCon .= $tmpA;

			$sumtotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumSubIncome += $Rows -> SubIncome;
			$sumSubRateResult += $Rows -> SubRateResult;
			$sumMainRateResult += $Rows -> MainRateResult;
			$sumStockResult += $Rows -> StockResult;
			$sumStockRateResult += $Rows -> StockRateResult;
			$sumDirectorRateResult += $Rows -> DirectorRateResult;
			$sumrealMemStake += $Rows -> realMemStake;
			$sumDirectorComm += $Rows -> DirectorComm;

			$Ctotals += $Rows -> totals;
			$CComm += $Rows -> RealCommission;
			$CMemStake += $Rows -> MemStake;
			$CSubIncome += $Rows -> SubIncome;
			$CSubRateResult += $Rows -> SubRateResult;
			$CMainRateResult += $Rows -> MainRateResult;
			$CStockResult += $Rows -> StockResult;
			$CStockRateResult += $Rows -> StockRateResult;
			$CDirectorRateResult += $Rows -> DirectorRateResult;
			$CDirectorComm += $Rows -> DirectorComm;
			//$CrealMemStake += $Rows -> realMemStake;
		}
	}
	$tmpG = str_replace("{Show_Director}",$arrAccount[$DirectorID], $G[1]);
	$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
	$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
	$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f", $sumSubIncome), $tmpG);
	$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f", $sumSubRateResult), $tmpG);
	$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f", $sumMainRateResult), $tmpG);
	$tmpG = str_replace("{sumStockResult}", sprintf("%.1f", $sumStockResult), $tmpG);
	$tmpG = str_replace("{sumStockRateResult}", sprintf("%.1f", $sumStockRateResult), $tmpG);
	$tmpG = str_replace("{sumDirectorComm}", sprintf("%.2f", $sumDirectorComm), $tmpG);
	$tmpG = str_replace("{sumDirectorRateWin}", sprintf("%.1f", $sumStockRateResult - $sumDirectorRateResult - $sumDirectorComm), $tmpG);
	$tmpG = str_replace("{sumDirectorWin}", sprintf("%.1f", $sumStockRateResult - $sumDirectorRateResult), $tmpG);
	$tmpG = str_replace("{sumDirectorRateResult}", sprintf("%.1f", $sumDirectorRateResult), $tmpG);
	$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f", $sumrealMemStake), $tmpG);
	if($isShowSupple){
		$intTmp = ($CrealMemStake == 0)?1:$CrealMemStake;
		$tmpG = str_replace("{sumrealMemStake%}", sprintf("%.4f", $sumrealMemStake / $intTmp), $tmpG);
	}else{
		$intTmp = ($sumrealMemStake == 0)?1:$sumrealMemStake;
		$tmpG = str_replace("{sumrealMemStake%}", sprintf("%.4f", $sumrealMemStake / $intTmp), $tmpG);
	}
	$strCon .= $tmpG;
	$fp = preg_replace("/<!--@ StockResult Start @\/\/-->.+<!--@ DirectorResult End @\/\/-->/s", $strCon, $fp);

/**************************************************************************/
//總監補貨
	if($isShowSupple){
		$strCon = "";
		$sumtotals = 0;
		$sumMemStake = 0;
		$sumSubIncome = 0;
		$sumSubRateResult = 0;
		$sumMainRateResult = 0;
		$sumStockResult = 0;
		$sumStockRateResult = 0;
		$sumrealMemStake = 0;
		$sumDirectorRateResult = 0;
		$sumDirectorSuppleWin = 0;
		$sumDirectorComm = 0;
		if(is_array($arrRows[1])){
			while(list($k, $Rows) = each($arrRows[1])){
				$DirectorID = $Rows -> DirectorID;
				$tmpA = $SA[1];
				//總帳
				if($intReportType == 0){
					$tmpA = str_replace("{Show_Stock}", $arrAccount[$Rows -> StockID], $tmpA);
					$tmpA = str_replace("{Show_StockID}", $Rows -> StockID, $tmpA);
				//分類帳
				}elseif($intReportType == 1){
					$tmpA = str_replace("{Show_Stock}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $tmpA);
					$tmpA = str_replace("BetSupple('{Show_StockID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 5)", $tmpA);
				}
				$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
				$tmpA = str_replace("{MemStake}", sprintf("%.1f",$Rows -> MemStake), $tmpA);
				$tmpA = str_replace("{SubIncome}", sprintf("%.1f",$Rows -> SubIncome), $tmpA);
				$tmpA = str_replace("{SubRateResult}", sprintf("%.1f",$Rows -> SubRateResult), $tmpA);
				$tmpA = str_replace("{realMemStake}", sprintf("%.1f",$Rows -> realMemStake), $tmpA);
				$tmpA = str_replace("{realMemStake%}", sprintf("%.4f",$Rows -> realMemStake / $CrealMemStake), $tmpA);
				$tmpA = str_replace("{MainRateResult}", sprintf("%.1f",$Rows -> MainRateResult), $tmpA);
				$tmpA = str_replace("{StockResult}", sprintf("%.1f",$Rows -> StockResult), $tmpA);
				$tmpA = str_replace("{StockRateResult}", sprintf("%.1f",$Rows -> StockRateResult), $tmpA);
				$tmpA = str_replace("{DirectorResult}", sprintf("%.1f",$Rows -> DirectorResult), $tmpA);
				$tmpA = str_replace("{DirectorStockRate}", $Rows -> StockRate - $Rows -> DirectorRate, $tmpA);
				$tmpA = str_replace("{DirectorRate}", $Rows -> DirectorRate, $tmpA);
				$tmpA = str_replace("{DirectorComm}", sprintf("%.2f",$Rows -> DirectorComm), $tmpA);
				$tmpA = str_replace("{DirectorRateWin}", sprintf("%.1f",0), $tmpA);
				$tmpA = str_replace("{DirectorWin}", sprintf("%.1f",$Rows -> StockRateResult - $Rows -> DirectorRateResult), $tmpA);
				$tmpA = str_replace("{DirectorRateResult}", sprintf("%.1f",$Rows -> DirectorRateResult), $tmpA);
				$strCon .= $tmpA;

				$sumtotals += $Rows -> totals;
				$sumMemStake += $Rows -> MemStake;
				$sumSubIncome += $Rows -> SubIncome;
				$sumSubRateResult += $Rows -> SubRateResult;
				$sumMainRateResult += $Rows -> MainRateResult;
				$sumStockResult += $Rows -> StockResult;
				$sumStockRateResult += $Rows -> StockRateResult;
				$sumDirectorRateResult += $Rows -> DirectorRateResult;
				$sumrealMemStake += $Rows -> realMemStake;
				$sumDirectorSuppleWin += $Rows -> DirectorRateResult*-1;
				$sumDirectorComm += $Rows -> DirectorComm;

				$Ctotals += $Rows -> totals;
				$CComm += $Rows -> RealCommission;
				$CMemStake += $Rows -> MemStake;
				$CSubIncome += $Rows -> SubIncome;
				$CSubRateResult += $Rows -> SubRateResult;
				$CMainRateResult += $Rows -> MainRateResult;
				$CStockResult += $Rows -> StockResult;
				$CStockRateResult += $Rows -> StockRateResult;
				$CDirectorRateResult += $Rows -> DirectorRateResult;
				$CDirectorComm += $Rows -> DirectorComm;
				//$CrealMemStake += $Rows -> realMemStake;
			}
		}
		$tmpG = str_replace("{Show_Director}",$arrAccount[$DirectorID], $SG[1]);
		$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
		$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
		$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f", $sumSubIncome), $tmpG);
		$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f", $sumSubRateResult), $tmpG);
		$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f", $sumMainRateResult), $tmpG);
		$tmpG = str_replace("{sumStockResult}", sprintf("%.1f", $sumStockResult), $tmpG);
		$tmpG = str_replace("{sumStockRateResult}", sprintf("%.1f", $sumStockRateResult), $tmpG);
		$tmpG = str_replace("{sumDirectorComm}", sprintf("%.2f", $sumDirectorComm), $tmpG);
		$tmpG = str_replace("{sumDirectorRateWin}", sprintf("%.1f", $sumStockRateResult - $sumDirectorRateResult - $sumDirectorComm), $tmpG);
		$tmpG = str_replace("{sumDirectorWin}", sprintf("%.1f", ($sumStockRateResult - $sumDirectorRateResult)), $tmpG);
		$tmpG = str_replace("{sumDirectorRateResult}", sprintf("%.1f", $sumDirectorRateResult), $tmpG);
		$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f", $sumrealMemStake), $tmpG);
		$intTmp = ($CrealMemStake == 0)?1:$CrealMemStake;
		$tmpG = str_replace("{sumrealMemStake%}", sprintf("%.4f", $sumrealMemStake / $intTmp), $tmpG);
		$strCon .= $tmpG;
		$fp = preg_replace("/<!--@ SuppleStockResult Start @\/\/-->.+<!--@ SuppleDirectorResult End @\/\/-->/s", $strCon, $fp);
	} //if($isShowSupple)

/**************************************************************************/
//公司補貨
	$tmpS = $S[1];
	if($isShowComSupple){
		$strCon = "";
		$sumtotals = 0;
		$sumMemStake = 0;
		$sumStockRateResult = 0;
		if(is_array($arrRows[1])){
			while(list($k, $Rows) = each($arrRows[1])){
				$tmpA = $CA[1];
				//總帳
				if($intReportType == 0){
					$tmpA = str_replace("{Show_Director}", $arrAccount[$Rows -> MemID], $tmpA);
					$tmpA = str_replace("{Show_DirectorID}", $Rows -> MemID, $tmpA);
				//分類帳
				}elseif($intReportType == 1){
					$tmpA = str_replace("{Show_Director}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $tmpA);
					$tmpA = str_replace("ComSupple('{Show_DirectorID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 1)", $tmpA);
				}

				$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
				$tmpA = str_replace("{MemStake}", sprintf("%.1f",$Rows -> MemStake), $tmpA);
				$tmpA = str_replace("{StockRateResult}", sprintf("%.1f",$Rows -> StockRateResult), $tmpA);
				$strCon .= $tmpA;

				$sumtotals += $Rows -> totals;
				$sumMemStake += $Rows -> MemStake;
				$sumStockRateResult += $Rows -> StockRateResult;

				$Ctotals += $Rows -> totals;
				$CComm += $Rows -> RealCommission;
				$CMemStake += $Rows -> MemStake;
				$CStockRateResult += $Rows -> StockRateResult;
			}
		}
		$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $CG[1]);
		$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
		$tmpG = str_replace("{sumStockRateResult}", sprintf("%.1f", $sumStockRateResult), $tmpG);
		$strCon .= $tmpG;
		$fp = preg_replace("/<!--@ SuppleComResult Start @\/\/-->.+<!--@ SuppleCompanyResult End @\/\/-->/s", $strCon, $fp);

		$tmpS = str_replace("{CComm}", sprintf("%.1f", $CComm), $tmpS);
		$tmpS = str_replace("{CWinLose}", sprintf("%.1f", ($CStockRateResult - $CComm)), $tmpS);
	} //if($isShowComSupple)


	$tmpS = str_replace("{Ctotals}", number_format($Ctotals), $tmpS);
	$tmpS = str_replace("{CMemStake}", sprintf("%.1f", $CMemStake), $tmpS);
	$tmpS = str_replace("{CSubIncome}", sprintf("%.1f", $CSubIncome), $tmpS);
	$tmpS = str_replace("{CSubRateResult}", sprintf("%.1f", $CSubRateResult), $tmpS);
	$tmpS = str_replace("{CMainRateResult}", sprintf("%.1f", $CMainRateResult), $tmpS);
	$tmpS = str_replace("{CStockResult}", sprintf("%.1f", $CStockResult), $tmpS);
	$tmpS = str_replace("{CStockRateResult}", sprintf("%.1f", $CStockRateResult), $tmpS);
	$tmpS = str_replace("{CDirectorComm}", sprintf("%.2f", $CDirectorComm), $tmpS);
	$tmpS = str_replace("{CDirectorRateWin}", sprintf("%.1f", $CStockRateResult - $CDirectorRateResult + $sumDirectorSuppleWin - $CDirectorComm), $tmpS);
	$tmpS = str_replace("{CDirectorWin}", sprintf("%.1f", $CStockRateResult - $CDirectorRateResult + $sumDirectorSuppleWin), $tmpS);
	$tmpS = str_replace("{CDirectorRateResult}", sprintf("%.1f", $CDirectorRateResult), $tmpS);
	$tmpS = str_replace("{CrealMemStake}", sprintf("%.1f", $CrealMemStake), $tmpS);
	$intTmp = ($CrealMemStake == 0)?1:$CrealMemStake;
	$tmpS = str_replace("{CrealMemStake%}", sprintf("%.4f", $CrealMemStake / $intTmp), $tmpS);
	$fp = preg_replace("/<!--@ ALLResult Start @\/\/-->.+<!--@ ALLResult End @\/\/-->/s", $tmpS, $fp);

$fp .= "\n<a style='font-size: 10px; color: #DDDDDD'>".(string)($time_end - $time_start)."</a>";
//輸出
WebOutputHTML($fp, 1);
?>
